package io.jpress.commons;

import io.jboot.aop.ValueFilter;
import io.jboot.utils.StrUtil;

public class OrderByFilter implements ValueFilter {

    private static final String[] FILTER_SYMBOLS = "+ - / * # \" ' > < = ( ) ;".split(" ");
    private static final String[] FILTER_WORDS = "select insert update delete where".split(" ");

    @Override
    public Object doFilter(Object orignal) {
        if (StrUtil.isBlank((String) orignal)) {
            return null;
        }
        for (String symbol : FILTER_SYMBOLS) {
            if (((String) orignal).contains(symbol)) {
                return null;
            }
        }
        String lowerCase = ((String) orignal).toLowerCase();
        for (String filterWord : FILTER_WORDS) {
            if ((lowerCase).contains(filterWord)) {
                return null;
            }
        }
        return orignal;
    }
}
